import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "./plugins/element.js";
import "normalize.css/normalize.css";
import "@/assets/css/public.css";
//引入数据请求Api
import * as Api from "@/http/api";
//引入时间格式
import Moment from "moment";

Vue.config.productionTip = false;
//将axios请求挂载到vue原型上
Vue.prototype.$http = Api;
//定义全局过滤器
Vue.filter("rank", function (v) {
  // console.log(v, "需要处理的V");

  let result;
  switch (v + "") {
    case "0":
      result = "一级";
      break;
    case "1":
      result = "二级";
      break;
    case "3":
      result = "三级";
      break;
    default:
      result = "三级";
  }
  return result;
});

//全局时间
Vue.filter("time", function (v) {
  Moment.locale("zh-cn");
  return Moment(v * 1000).format("YYYY-MM-DD HH:mm:ss a");
});

//富文本引入全局
import VueQuillEditor from "vue-quill-editor";

// require styles
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";

//拖拽
Vue.directive("drag", function (el, binding, vnode) {
  el.onmousedown = function (e) {
    console.log(e.clientX); //点击位置距离左边的距离
    console.log(el.offsetLeft); //盒子距离左边的距离
    const a = e.clientX - el.offsetLeft;
    const b = e.clientY - el.offsetTop;
    document.onmousemove = function (ev) {
      //onmousemove 鼠标移动事件
      console.log(ev);
      let left = ev.clientX - a < 0 ? 0 : ev.clientX - a;
      let top = ev.clientY - b < 0 ? -100 : ev.clientY - b;
      el.style.position = "absolute";
      el.style.left = left + "px";
      el.style.top = top + "px";
    };
  };
  document.onmouseup = function () {
    //onmouseup 鼠标抬起事件
    document.onmousedown = null;
    document.onmousemove = null;
  };
});

Vue.use(VueQuillEditor);

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
